<!--
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<ng-container [formGroup]="labelForm">
  <div formArrayName="labels">
    <div *ngFor="let label of labels.controls; let i = index;"
         [formGroupName]="i">
      <mat-form-field md-no-float
                      class="kd-deploy-input-row"
                      fxFlex="45">
        <input matInput
               name="key"
               formControlName="key"
               (keyup)="check(i)"
               [readonly]="!label.get('editable').value"
               i18n-placeholder
               placeholder="key">
        <mat-error *ngIf="label.get('key').errors?.unique"
                   i18n>
          {{label.get('key').value}} is not unique
        </mat-error>
        <mat-error *ngIf="label.get('key').errors?.kdValidLabelKeyPrefixPattern"
                   i18n>
          Prefix is not a valid DNS subdomain prefix (eg. my-domain.com).
        </mat-error>
        <mat-error *ngIf="label.get('key').errors?.kdValidLabelKeyNamePattern"
                   i18n>
          Label key name must be alphanumeric separated by '-', '_' or '.', optionally prefixed by a DNS subdomain and '/'.
        </mat-error>
        <mat-error *ngIf="label.get('key').errors?.kdValidLabelKeyPrefixLength"
                   i18n>
          Prefix should not exceed 253 characters.
        </mat-error>
        <mat-error *ngIf="label.get('key').errors?.kdValidLabelKeyNameLength"
                   i18n>
          Label Key name should not exceed 63 characters.
        </mat-error>
      </mat-form-field>
      <p fxFlex="5"></p>
      <mat-form-field md-no-float
                      class="kd-deploy-input-row"
                      fxFlex="40">
        <input matInput
               name="value"
               formControlName="value"
               (keyup)="check(i)"
               [readonly]="!label.get('editable').value"
               i18n-placeholder
               placeholder="value">
        <mat-hint align="end">{{label.get('value').value?.length}} / 253</mat-hint>
        <mat-error *ngIf="label.get('value').errors?.kdValidLabelValuePattern"
                   i18n>
          Label value must be alphanumeric separated by '.' , '-' or '_'.
        </mat-error>
        <mat-error *ngIf="label.get('value').errors?.maxlength"
                   i18n>
          Label Value must not exceed 253 characters.
        </mat-error>
      </mat-form-field>
      <input type="hidden"
             formControlName="editable" />

      <div fxFlex="10">
        <button mat-icon-button
                *ngIf="isRemovable(i)"
                (click)="deleteLabel(i)">
          <mat-icon>delete</mat-icon>
        </button>
      </div>
    </div>
  </div>
</ng-container>
